package sz.com.postoffice.jxyzwgcase;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import com.github.drinkjava2.jsqlbox.DbContext;
import com.github.drinkjava2.jtransactions.spring.SpringTxConnectionManager;
import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

@SpringBootApplication(exclude = PageHelperAutoConfiguration.class)
/*
 * @ComponentScan(basePackages = { "sz.com.postoffice.jxyzwgcase",
 * "com.huawei.ucmarket" })
 */
@EnableScheduling
public class JxyzwgcaseApplication {
	@Autowired
	@Qualifier(value="masterDataSource")
	DataSource ds;
	
	public static void main(String[] args) {
		SpringApplication.run(JxyzwgcaseApplication.class, args);
	}

	
	@Bean
	public DbContext createDefaultDbContext() {
		DbContext ctx = new DbContext(ds);
		ctx.setConnectionManager(SpringTxConnectionManager.instance());
		ctx.setAllowShowSQL(true);
		DbContext.setGlobalDbContext(ctx);// 设定静态全局上下文
		return ctx;
	}

	/**
	 *
	 *〈简述〉修复同一时间无法执行多个 定时任务问题
	 * @return
	 */
	@Bean
	public TaskScheduler taskScheduler() {
		ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
		taskScheduler.setPoolSize(50);
		return taskScheduler;
	}

}
